﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>面试管理</title>
    <link rel="stylesheet" href="~/scripts/layui-v2.5.6/layui/css/layui.css">
    <link rel="stylesheet" href="~/css/interview-responsive.css">
    <style>
        /* 基础布局 */
        .layui-form {
            padding: 20px 30px 0 0;
        }
        .layui-card-body {
            padding: 15px;
        }
        .layui-table-cell {
            height: auto;
        }
        
        /* 响应式容器 */
        .responsive-container {
            width: 100%;
            overflow-x: auto;
            margin-bottom: 20px;
        }
        
        /* 树形表格自定义样式 */
        .tree-table {
            width: 100%;
            min-width: 1230px; /* 增加最小宽度以适应新的部门列 */
        }
        
        /* 父级行样式 */
        .parent-row {
            background-color: #f8f9fa !important;
            font-weight: 500;
            cursor: pointer;
        }
        
        .parent-row:hover {
            background-color: #e9ecef !important;
        }
        
        /* 子级行样式 */
        .child-row {
            background-color: #fff !important;
            display: none;
        }
        
        .child-row.show {
            display: table-row;
        }
        
        .child-row td:first-child {
            padding-left: 40px !important;
            position: relative;
        }
        
        .child-row td:first-child:before {
            content: "└─";
            position: absolute;
            left: 20px;
            color: #ccc;
        }
        
        /* 展开/收起图标 */
        .expand-icon {
            margin-right: 5px;
            font-size: 12px;
            transition: transform 0.3s;
            cursor: pointer;
        }
        
        .expand-icon.expanded {
            transform: rotate(90deg);
        }
        
        /* 状态标签样式 */
        .status-tag {
            padding: 2px 8px;
            border-radius: 3px;
            font-size: 12px;
            color: #fff;
            white-space: nowrap;
        }
        .status-pass { background-color: #5FB878; }
        .status-fail { background-color: #FF5722; }
        .status-pending { background-color: #FFB800; }
        
        /* 操作按钮样式 */
        .layui-btn-xs {
            margin-right: 5px;
            margin-bottom: 2px;
        }
        
        /* 分页样式 */
        .pagination-container {
            text-align: center;
            margin-top: 20px;
        }
        
        /* 操作列按钮排列 */
        .action-buttons {
            white-space: nowrap;
        }
        
        /* 搜索表单响应式 */
        .search-form-responsive {
            margin-bottom: 15px;
        }
        
        /* 工具栏响应式 */
        .toolbar-responsive {
            margin-bottom: 15px;
        }
        
        /* 表格响应式滚动条样式 */
        .responsive-container::-webkit-scrollbar {
            height: 8px;
        }
        
        .responsive-container::-webkit-scrollbar-track {
            background: #f1f1f1;
        }
        
        .responsive-container::-webkit-scrollbar-thumb {
            background: #c1c1c1;
            border-radius: 4px;
        }
        
        .responsive-container::-webkit-scrollbar-thumb:hover {
            background: #a8a8a8;
        }


    </style>
    

</head>
<body>
    <div class="layui-card">
        <div class="layui-card-header">
            <h2>面试管理</h2>
        </div>
        <div class="layui-card-body">
            <!-- 搜索区域 -->
            <form class="layui-form search-form-responsive" lay-filter="searchForm">
                @Html.AntiForgeryToken()
                <div class="layui-row layui-col-space15">
                    <div class="layui-col-md3 layui-col-sm6 layui-col-xs12">
                        <div class="layui-form-item">
                            <label class="layui-form-label">人员名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" placeholder="请输入人员名称" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3 layui-col-sm6 layui-col-xs12">
                        <div class="layui-form-item">
                            <label class="layui-form-label">面试官</label>
                            <div class="layui-input-block">
                                <input type="text" name="interviewer" placeholder="请输入面试官名称" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-sm12 layui-col-xs12">
                        <div class="layui-form-item">
                            <div class="layui-input-block" style="margin-left: 0; text-align: left;">
                                <button class="layui-btn" lay-submit lay-filter="search">
                                    <i class="layui-icon layui-icon-search"></i> 搜索
                                </button>
                                <button type="reset" class="layui-btn layui-btn-primary" id="resetBtn">
                                    <i class="layui-icon layui-icon-refresh"></i> 重置
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </form>

            <!-- 工具栏 -->
            <div class="layui-row toolbar-responsive">
                <div class="layui-col-md12">
                    <div class="layui-btn-group">
                        <button class="layui-btn layui-btn-sm" id="addBtn">
                            <i class="layui-icon layui-icon-add-1"></i> 新增
                        </button>
                    </div>
                </div>
            </div>

            <!-- 表格区域 -->
            <div class="responsive-container">
                <div class="layui-form">
                    <table class="layui-table tree-table" id="interviewTable">
                        <thead>
                            <tr>
                                <th width="100">人员名称</th>
                                <th width="130">联系电话</th>
                                <th width="80">用户性别</th>
                                <th width="120">归属部门</th>
                                <th width="80">定级</th>
                                <th width="180">面试反馈</th>
                                <th width="100">面试结果</th>
                                <th width="80">面试次数</th>
                                <th width="140">面试时间</th>
                                <th width="80">面试官</th>
                                <th width="120">操作</th>
                            </tr>
                        </thead>
                        <tbody id="tableBody">
                            <!-- 数据将通过JavaScript动态生成 -->
                        </tbody>
                    </table>
                </div>
            </div>

            <!-- 分页 -->
            <div class="pagination-container">
                <div id="pagination"></div>
            </div>
        </div>
    </div>

    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="~/scripts/layui-v2.5.6/layui/layui.js"></script>
    <script>
        layui.use(['form', 'layer', 'laypage'], function(){
            var form = layui.form;
            var layer = layui.layer;
            var laypage = layui.laypage;

            // 存储原始数据
            var rawData = [];
            var processedData = [];
            var currentPaginationInfo = { page: 1, limit: 10 }; // 存储当前分页信息

            // 获取面试数据
            function loadInterviewData(page, limit) {
                // 设置默认分页参数
                page = page || 1;
                limit = limit || 10; // 默认每页显示10条数据
                
                // 保存当前分页信息
                currentPaginationInfo = { page: page, limit: limit };
                
                // 首先调用第一个接口获取所有数据
                $.ajax({
                    url: '/InterviewMenagement/GetInterviewMenagementModel',
                    type: 'GET',
                    data: {
                        page: page,
                        limit: limit
                    },
                    dataType: 'json',
                    success: function(response) {
                        console.log('获取面试数据成功:', response);
                        console.log('响应数据类型:', typeof response);
                        console.log('响应数据结构:', response);
                        
                        // 处理分页响应格式
                        var allData = [];
                        if (response && response.listDate) {
                            allData = response.listDate;
                            console.log('使用 listDate 字段，数据长度:', allData.length);
                        } else if (Array.isArray(response)) {
                            allData = response;
                            console.log('使用数组格式，数据长度:', allData.length);
                        } else {
                            console.log('数据格式不匹配，response:', response);
                        }
                        
                        console.log('最终 allData:', allData);
                        
                        // 分离面试次数为0和不为0的数据
                        var zeroInterviewData = [];
                        var nonZeroInterviewData = [];
                        
                        allData.forEach(function(item) {
                            var interviewCount = parseInt(item.interviewsNumber) || 0;
                            if (interviewCount === 0) {
                                zeroInterviewData.push(item);
                            } else {
                                nonZeroInterviewData.push(item);
                            }
                        });
                        
                        console.log('面试次数为0的数据:', zeroInterviewData);
                        console.log('面试次数不为0的数据:', nonZeroInterviewData);
                        
                        // 如果有面试次数不为0的数据，调用第二个接口获取带部门信息的数据
                        if (nonZeroInterviewData.length > 0) {
                            // 获取面试次数不为0的数据的ID列表
                            var nonZeroIds = nonZeroInterviewData.map(function(item) {
                                return item.id;
                            });
                            
                            // 调用第二个接口
                            $.ajax({
                                url: '/InterviewMenagement/GetInterviewMenagementModelWithDepartment', // 第二个接口：带部门信息的接口
                                type: 'GET',
                                data: { 
                                    includeIds: nonZeroIds.join(','), // 传递ID列表
                                    includeDepartment: true, // 标识需要部门信息
                                    page: page,
                                    limit: limit
                                },
                                dataType: 'json',
                                success: function(departmentResponse) {
                                    console.log('获取带部门信息的数据成功:', departmentResponse);
                                    // 处理第二个接口的分页响应格式
                                    var departmentData = [];
                                    if (departmentResponse && departmentResponse.listDate) {
                                        departmentData = departmentResponse.listDate;
                                    } else if (Array.isArray(departmentResponse)) {
                                        departmentData = departmentResponse;
                                    }
                                    
                                    // 合并数据：面试次数为0的使用原始数据，面试次数不为0的使用带部门信息的数据
                                    rawData = [...zeroInterviewData, ...departmentData];
                                    
                                    // 传递第一个接口的分页信息
                                    var paginationInfo = {
                                        currentPage: page,
                                        totalPages: response.pageIndex || 1,  // pageIndex是总页数
                                        totalCount: response.pageCount || 0,  // pageCount是总行数
                                        limit: limit
                                    };
                                    processDataAndRender(paginationInfo);
                                },
                                error: function(xhr, status, error) {
                                    console.log('获取带部门信息的数据失败，使用原始数据:', error);
                                    // 如果第二个接口失败，使用原始数据
                                    rawData = allData;
                                    var paginationInfo = {
                                        currentPage: page,
                                        totalPages: response.pageIndex || 1,  // pageIndex是总页数
                                        totalCount: response.pageCount || 0,  // pageCount是总行数
                                        limit: limit
                                    };
                                    processDataAndRender(paginationInfo);
                                }
                            });
                        } else {
                            // 如果没有面试次数不为0的数据，直接使用原始数据
                            rawData = allData;
                            var paginationInfo = {
                                currentPage: page,
                                totalPages: response.pageIndex || 1,  // pageIndex是总页数
                                totalCount: response.pageCount || 0,  // pageCount是总行数
                                limit: limit
                            };
                            processDataAndRender(paginationInfo);
                        }
                    },
                    error: function(xhr, status, error) {
                        console.log('获取面试数据失败:', error);
                        layer.msg('获取面试数据失败，请稍后重试', {icon: 2});
                    }
                });
            }

            // 处理数据并渲染
            function processDataAndRender(paginationInfo) {
                console.log('最终合并的数据:', rawData);
                console.log('分页信息:', paginationInfo);
                
                // 转换数据格式
                var convertedData = convertApiDataToTableData(rawData);
                
                // 按人员分组
                processedData = groupByName(convertedData);
                
                // 渲染表格
                renderTable(processedData);
                
                // 更新分页信息 - 使用服务器返回的分页信息
                if (paginationInfo && paginationInfo.totalCount) {
                    updatePagination(paginationInfo.totalCount, paginationInfo);
                } else {
                    updatePagination(rawData.length);
                }
            }

            // 转换API数据格式为表格数据格式
            function convertApiDataToTableData(apiData) {
                return apiData.map(function(item) {
                    // 格式化面试时间
                    var formattedTime = '';
                    if (item.interviewsTime) {
                        try {
                            var date = new Date(item.interviewsTime);
                            if (!isNaN(date.getTime())) {
                                // 格式化为 YYYY-MM-DD HH:mm
                                var year = date.getFullYear();
                                var month = (date.getMonth() + 1).toString().padStart(2, '0');
                                var day = date.getDate().toString().padStart(2, '0');
                                var hours = date.getHours().toString().padStart(2, '0');
                                var minutes = date.getMinutes().toString().padStart(2, '0');
                                formattedTime = `${year}-${month}-${day} ${hours}:${minutes}`;
                            }
                        } catch (e) {
                            console.error('时间格式化错误:', e);
                            formattedTime = item.interviewsTime;
                        }
                    }

                    return {
                        id: item.id,
                        personnelCode: item.personnelCode || '',
                        name: item.personnelName || '',
                        phone: item.phone || '',
                        gender: item.sex === 1 ? '男' : (item.sex === 0 ? '女' : '未知'),
                        departmentName: item.departmentName || (parseInt(item.interviewsNumber) === 0 ? '待分配' : ''), // 面试次数为0时显示"待分配"
                        level: item.definiteIntegral || '',
                        department: item.affiliatedDepartment || '', // 保留原有字段以防其他地方使用
                        wage: item.postWage || '',
                        roles: item.roles || '',
                        feedback: item.interviewFeedback || '',
                        result: item.interviewResult || '待选',
                        count: item.interviewsNumber || 0,
                        time: formattedTime,
                        interviewer: item.interviewer || ''
                    };
                });
            }

            // 渲染表格数据
            function renderTable(data) {
                var tbody = document.getElementById('tableBody');
                tbody.innerHTML = '';

                if(!data || data.length === 0) {
                    // 显示空状态
                    var emptyRow = document.createElement('tr');
                    emptyRow.innerHTML = `
                        <td colspan="11" style="text-align: center; padding: 50px; color: #999;">
                            <i class="layui-icon layui-icon-face-cry" style="font-size: 48px; display: block; margin-bottom: 20px;"></i>
                            暂无面试数据
                        </td>
                    `;
                    tbody.appendChild(emptyRow);
                    return;
                }

                data.forEach(function(item, index) {
                    // 创建父级行
                    var parentRow = createParentRow(item, index);
                    tbody.appendChild(parentRow);

                    // 创建子级行
                    if (item.children && item.children.length > 0) {
                        item.children.forEach(function(child, childIndex) {
                            var childRow = createChildRow(child, index, childIndex);
                            tbody.appendChild(childRow);
                        });
                    }
                });
            }

            // 创建父级行
            function createParentRow(item, index) {
                var tr = document.createElement('tr');
                tr.className = 'parent-row';
                tr.setAttribute('data-parent-id', index);
                
                var hasChildren = item.children && item.children.length > 0;
                var expandIcon = hasChildren ? '<i class="layui-icon layui-icon-right expand-icon" data-parent="' + index + '"></i>' : '';
                
                tr.innerHTML = `
                    <td>${expandIcon}${item.name}</td>
                    <td>${item.phone}</td>
                    <td style="text-align: center;">${item.gender}</td>
                    <td style="text-align: center;">${item.departmentName}</td>
                    <td style="text-align: center;">${item.level}</td>
                    <td>${item.feedback}</td>
                    <td style="text-align: center;">${getStatusHtml(item.result)}</td>
                    <td style="text-align: center;">${item.count}</td>
                    <td style="text-align: center;">${item.time}</td>
                    <td style="text-align: center;">${item.interviewer}</td>
                    <td style="text-align: center;">
                        <div class="action-buttons">
                            <button class="layui-btn layui-btn-xs" onclick="addInterview(${item.id})">邀请面试</button>
                        </div>
                    </td>
                `;
                
                return tr;
            }

            // 创建子级行
            function createChildRow(item, parentIndex, childIndex) {
                var tr = document.createElement('tr');
                tr.className = 'child-row';
                tr.setAttribute('data-parent', parentIndex);
                
                tr.innerHTML = `
                    <td>${item.name}</td>
                    <td>${item.phone}</td>
                    <td style="text-align: center;">${item.gender}</td>
                    <td style="text-align: center;">${item.departmentName}</td>
                    <td style="text-align: center;">${item.level}</td>
                    <td>${item.feedback}</td>
                    <td style="text-align: center;">${getStatusHtml(item.result)}</td>
                    <td style="text-align: center;">${item.count}</td>
                    <td style="text-align: center;">${item.time}</td>
                    <td style="text-align: center;">${item.interviewer}</td>
                    <td style="text-align: center;">
                        <div class="action-buttons">
                            <button class="layui-btn layui-btn-xs" onclick="editInterview(${item.id})">反馈</button>
                            <button class="layui-btn layui-btn-xs layui-btn-danger" onclick="deleteInterview(${item.id})">删除</button>
                        </div>
                    </td>
                `;
                
                return tr;
            }

            // 获取状态HTML
            function getStatusHtml(result) {
                var className = '';
                switch(result) {
                    case '通过':
                        className = 'status-pass';
                        break;
                    case '面试':
                        className = 'status-fail';
                        break;
                    default:
                        className = 'status-pending';
                }
                return `<span class="status-tag ${className}">${result}</span>`;
            }

            // 展开/收起事件
            document.addEventListener('click', function(e) {
                if (e.target.classList.contains('expand-icon')) {
                    var parentIndex = e.target.getAttribute('data-parent');
                    var childRows = document.querySelectorAll(`tr[data-parent="${parentIndex}"]`);
                    var icon = e.target;
                    
                    if (icon.classList.contains('expanded')) {
                        // 收起
                        childRows.forEach(function(row) {
                            row.classList.remove('show');
                        });
                        icon.classList.remove('expanded');
                        icon.classList.remove('layui-icon-down');
                        icon.classList.add('layui-icon-right');
                    } else {
                        // 展开
                        childRows.forEach(function(row) {
                            row.classList.add('show');
                        });
                        icon.classList.add('expanded');
                        icon.classList.remove('layui-icon-right');
                        icon.classList.add('layui-icon-down');
                    }
                }
            });

            // 点击父级行也可以展开/收起
            document.addEventListener('click', function(e) {
                if (e.target.closest('.parent-row') && !e.target.classList.contains('layui-btn')) {
                    var parentRow = e.target.closest('.parent-row');
                    var expandIcon = parentRow.querySelector('.expand-icon');
                    if (expandIcon) {
                        expandIcon.click();
                    }
                }
            });

            // 操作函数
            window.addInterview = function(id) {
                console.log('邀请面试，人员ID:', id);
                showInterviewInviteModal(id);
            };

            window.editInterview = function(id) {
                console.log('反馈面试，记录ID:', id);
                console.log('ID类型:', typeof id);
                console.log('ID是否有效:', id !== undefined && id !== null && id !== '');
                
                // 检查rawData中是否存在该ID
                var foundRecord = rawData.find(function(item) {
                    return item.id == id; // 使用 == 允许类型转换
                });
                console.log('在rawData中找到的记录:', foundRecord);
                
                showInterviewFeedbackModal(id);
            };

            window.deleteInterview = function(id) {
                layer.confirm('确定删除这条面试记录吗？', {
                    title: '删除确认',
                    icon: 3,
                    btn: ['确定删除', '取消']
                }, function(index){
                    // 确认删除
                    layer.close(index);
                    
                    console.log('删除面试记录，ID:', id);
                    console.log('ID类型:', typeof id);
                    
                    // 获取防伪标记
                    var token = $('input[name="__RequestVerificationToken"]').val();
                    console.log('防伪标记:', token);
                    
                    // MVC方式传参 - 使用表单序列化方式
                    var deleteData = {
                        'id': parseInt(id),
                        '__RequestVerificationToken': token
                    };
                    
                    console.log('准备发送的数据:', deleteData);
                    
                    // 调用删除接口 - 根据Swagger显示的路径参数方式
                    $.ajax({
                        url: '/InterviewMenagement/DeleleteInterviewMenagement/' + parseInt(id),
                        type: 'POST',
                        data: {
                            '__RequestVerificationToken': token
                        },
                        beforeSend: function() {
                            layer.load(1, {shade: [0.3, '#000']});
                        },
                        success: function(res) {
                            layer.closeAll('loading');
                            console.log('删除响应结果:', res);
                            
                            // 判断删除结果：1代表成功，0代表失败
                            if(res === 1 || res === '1') {
                                layer.msg('删除成功', {
                                    icon: 1,
                                    time: 1500
                                }, function() {
                                    // 重新加载数据
                                    var currentPage = getCurrentPage();
                                    var currentLimit = getCurrentLimit();
                                    
                                    // 判断是搜索状态还是普通状态
                                    var searchForm = document.querySelector('form[lay-filter="searchForm"]');
                                    var formData = new FormData(searchForm);
                                    var searchParams = {};
                                    for (var [key, value] of formData.entries()) {
                                        if (value.trim()) {
                                            searchParams[key] = value.trim();
                                        }
                                    }
                                    
                                    if (Object.keys(searchParams).length > 0) {
                                        // 有搜索条件，执行搜索
                                        loadInterviewDataWithSearch(searchParams, currentPage, currentLimit);
                                    } else {
                                        // 无搜索条件，普通加载
                                        loadInterviewData(currentPage, currentLimit);
                                    }
                                });
                            } else {
                                layer.msg('删除失败', {icon: 2});
                            }
                        },
                        error: function(xhr, status, error) {
                            layer.closeAll('loading');
                            console.error('删除请求失败:', error);
                            console.error('响应内容:', xhr.responseText);
                            
                            var errorMessage = '删除失败';
                            try {
                                if (xhr.responseText) {
                                    var response = JSON.parse(xhr.responseText);
                                    errorMessage = response.message || response.error || '删除失败';
                                }
                            } catch (e) {
                                console.error('解析错误信息失败:', e);
                            }
                            
                            layer.msg(errorMessage, {icon: 2});
                        }
                    });
                }, function(index){
                    // 取消删除
                    layer.close(index);
                });
            };

            // 显示面试反馈弹窗
            function showInterviewFeedbackModal(interviewId) {
                console.log('showInterviewFeedbackModal - 接收到的ID:', interviewId);
                console.log('showInterviewFeedbackModal - ID类型:', typeof interviewId);
                console.log('showInterviewFeedbackModal - rawData长度:', rawData.length);
                console.log('showInterviewFeedbackModal - rawData前3条记录的ID:', rawData.slice(0, 3).map(function(item) { return {id: item.id, type: typeof item.id}; }));
                
                // 查找对应的面试记录
                var interviewRecord = null;
                for(var i = 0; i < rawData.length; i++) {
                    console.log(`比较: rawData[${i}].id(${rawData[i].id}) === interviewId(${interviewId}) = ${rawData[i].id === interviewId}`);
                    console.log(`类型转换比较: rawData[${i}].id(${rawData[i].id}) == interviewId(${interviewId}) = ${rawData[i].id == interviewId}`);
                    if(rawData[i].id == interviewId) { // 使用 == 允许类型转换
                        interviewRecord = rawData[i];
                        console.log('找到匹配的记录:', interviewRecord);
                        break;
                    }
                }
                
                if(!interviewRecord) {
                    console.log('未找到面试记录，interviewId:', interviewId);
                    layer.msg('未找到对应的面试记录，ID: ' + interviewId, {icon: 2});
                    return;
                }
                
                // 计算弹窗尺寸
                var windowWidth = window.innerWidth || document.documentElement.clientWidth;
                var windowHeight = window.innerHeight || document.documentElement.clientHeight;
                
                var modalWidth, modalHeight;
                
                if (windowWidth <= 768) {
                    modalWidth = Math.min(windowWidth * 0.95, 500) + 'px';
                    modalHeight = Math.min(windowHeight * 0.8, 600) + 'px';
                } else if (windowWidth <= 1200) {
                    modalWidth = Math.min(windowWidth * 0.8, 700) + 'px';
                    modalHeight = Math.min(windowHeight * 0.75, 650) + 'px';
                } else {
                    modalWidth = '800px';
                    modalHeight = '650px';
                }
                
                // 打开面试反馈弹窗
                layer.open({
                    type: 1,
                    title: '<i class="layui-icon layui-icon-edit"></i> 面试反馈',
                    area: [modalWidth, modalHeight],
                    resize: false,
                    maxmin: true,
                    content: `
                        <style>
                            .feedback-modal .info-card {
                                background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
                                border-radius: 8px;
                                padding: 20px;
                                margin-bottom: 25px;
                                color: white;
                                box-shadow: 0 4px 15px rgba(102, 126, 234, 0.2);
                            }
                            .feedback-modal .info-item {
                                display: flex;
                                align-items: center;
                                margin-bottom: 10px;
                                font-size: 15px;
                            }
                            .feedback-modal .info-item:last-child {
                                margin-bottom: 0;
                            }
                            .feedback-modal .info-icon {
                                width: 20px;
                                height: 20px;
                                background: rgba(255,255,255,0.2);
                                border-radius: 50%;
                                display: flex;
                                align-items: center;
                                justify-content: center;
                                margin-right: 12px;
                                font-size: 12px;
                            }
                            .feedback-modal .form-section {
                                background: #fff;
                                border-radius: 8px;
                                padding: 25px;
                                margin-bottom: 20px;
                                box-shadow: 0 2px 8px rgba(0,0,0,0.06);
                                border: 1px solid #f0f0f0;
                            }
                            .feedback-modal .section-title {
                                font-size: 16px;
                                font-weight: 600;
                                color: #333;
                                margin-bottom: 15px;
                                padding-bottom: 8px;
                                border-bottom: 2px solid #667eea;
                                display: flex;
                                align-items: center;
                            }
                            .feedback-modal .section-title i {
                                margin-right: 8px;
                                color: #667eea;
                            }
                            .feedback-modal .custom-textarea {
                                width: 100%;
                                border: 2px solid #e8e8e8;
                                border-radius: 6px;
                                padding: 12px 15px;
                                font-size: 14px;
                                line-height: 1.6;
                                resize: none;
                                transition: all 0.3s ease;
                                font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
                            }
                            .feedback-modal .custom-textarea:focus {
                                border-color: #667eea;
                                box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
                                outline: none;
                            }
                            .feedback-modal .custom-select {
                                width: 100%;
                                height: 45px;
                                border: 2px solid #e8e8e8;
                                border-radius: 6px;
                                padding: 0 15px;
                                font-size: 14px;
                                background: #fff;
                                transition: all 0.3s ease;
                            }
                            .feedback-modal .custom-select:focus {
                                border-color: #667eea;
                                box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
                                outline: none;
                            }
                            .feedback-modal .required-label {
                                color: #ff4757;
                                font-weight: 600;
                            }
                            .feedback-modal .optional-label {
                                color: #666;
                                font-weight: 500;
                            }
                            .feedback-modal .btn-container {
                                text-align: center;
                                padding: 25px 30px;
                                background: linear-gradient(to right, #f8f9fa, #e9ecef);
                                border-top: 1px solid #dee2e6;
                            }
                            .feedback-modal .btn-submit {
                                background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
                                border: none;
                                color: white;
                                padding: 12px 30px;
                                border-radius: 6px;
                                font-size: 14px;
                                font-weight: 500;
                                margin-right: 15px;
                                transition: all 0.3s ease;
                                box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
                            }
                            .feedback-modal .btn-submit:hover {
                                transform: translateY(-2px);
                                box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
                            }
                            .feedback-modal .btn-cancel {
                                background: #fff;
                                border: 2px solid #ddd;
                                color: #666;
                                padding: 10px 30px;
                                border-radius: 6px;
                                font-size: 14px;
                                font-weight: 500;
                                transition: all 0.3s ease;
                            }
                            .feedback-modal .btn-cancel:hover {
                                border-color: #999;
                                color: #333;
                                transform: translateY(-1px);
                            }
                        </style>
                        <div class="feedback-modal" style="height: 100%; display: flex; flex-direction: column; background: #f5f7fa;">
                            <form class="layui-form" style="height: 100%; display: flex; flex-direction: column;">
                                <input type="hidden" name="InterviewId" value="${interviewId}" id="hiddenInterviewId">
                                
                                <div style="flex: 1; padding: 25px; overflow-y: auto;">
                                    <!-- 面试人员信息卡片 -->
                                    <div class="info-card">
                                        <div class="layui-row">
                                            <div class="layui-col-md4">
                                                <div class="info-item">
                                                    <div class="info-icon"><i class="layui-icon layui-icon-username"></i></div>
                                                    <div>
                                                        <div style="font-size: 12px; opacity: 0.8;">人员名称</div>
                                                        <div style="font-weight: 600; font-size: 16px;">${interviewRecord.personnelName || '未知'}</div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="layui-col-md4">
                                                <div class="info-item">
                                                    <div class="info-icon"><i class="layui-icon layui-icon-cellphone"></i></div>
                                                    <div>
                                                        <div style="font-size: 12px; opacity: 0.8;">联系电话</div>
                                                        <div style="font-weight: 600; font-size: 16px;">${interviewRecord.phone || '未知'}</div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="layui-col-md4">
                                                <div class="info-item">
                                                    <div class="info-icon"><i class="layui-icon layui-icon-date"></i></div>
                                                    <div>
                                                        <div style="font-size: 12px; opacity: 0.8;">面试次数</div>
                                                        <div style="font-weight: 600; font-size: 16px;">第 ${interviewRecord.interviewsNumber || 0} 次</div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    
                                    <!-- 面试反馈区域 -->
                                    <div class="form-section">
                                        <div class="section-title">
                                            <i class="layui-icon layui-icon-edit"></i>
                                            面试反馈
                                        </div>
                                        <div style="margin-bottom: 8px;">
                                            <span class="required-label">* 面试反馈</span>
                                            <span style="color: #999; font-size: 12px; margin-left: 10px;">请详细描述面试过程和候选人表现</span>
                                        </div>
                                        <textarea name="interviewFeedback" placeholder="请输入详细的面试反馈内容，包括候选人的技能水平、沟通能力、工作态度等方面的评价..." class="custom-textarea" lay-verify="required" style="height: 120px;">${interviewRecord.interviewFeedback || ''}</textarea>
                                    </div>
                                    
                                    <!-- 面试结果区域 -->
                                    <div class="form-section">
                                        <div class="section-title">
                                            <i class="layui-icon layui-icon-ok-circle"></i>
                                            面试结果
                                        </div>
                                        <div style="margin-bottom: 8px;">
                                            <span class="required-label">* 本次面试结果</span>
                                            <span style="color: #999; font-size: 12px; margin-left: 10px;">请根据面试情况选择结果</span>
                                        </div>
                                                                                 <select name="interviewResult" class="custom-select" lay-verify="required">
                                            <option value="">请选择面试结果</option>
                                            <option value="待复试" ${interviewRecord.interviewResult === '待复试' ? 'selected' : ''}>📝 待复试</option>
                                            <option value="面试通过" ${interviewRecord.interviewResult === '面试通过' ? 'selected' : ''}>✅ 面试通过</option>
                                            <option value="面试失败" ${interviewRecord.interviewResult === '面试失败' ? 'selected' : ''}>❌ 面试失败</option>
                                            <option value="待定" ${interviewRecord.interviewResult === '待定' ? 'selected' : ''}>⏳ 待定</option>
                                        </select>
                                    </div>
                                    
                                    
                                </div>
                                
                                <div class="btn-container">
                                    <button class="btn-submit" lay-submit lay-filter="feedbackForm" type="submit">
                                        <i class="layui-icon layui-icon-ok" style="margin-right: 5px;"></i>
                                        提交反馈
                                    </button>
                                    <button type="button" class="btn-cancel" onclick="layer.closeAll()">
                                        <i class="layui-icon layui-icon-close" style="margin-right: 5px;"></i>
                                        取消
                                    </button>
                                </div>
                            </form>
                        </div>
                    `,
                    success: function(layero, index){
                        // 重新渲染表单元素
                        form.render();
                        
                        // 监听表单提交
                        form.on('submit(feedbackForm)', function(data) {
                            var formData = data.field;
                            console.log('=== 反馈表单提交调试信息 ===');
                            console.log('面试反馈数据:', formData);
                            console.log('面试记录ID (formData.InterviewId):', formData.InterviewId, '类型:', typeof formData.InterviewId);
                            console.log('面试记录ID (interviewId参数):', interviewId, '类型:', typeof interviewId);
                            
                            var hiddenElement = document.getElementById('hiddenInterviewId');
                            console.log('隐藏字段元素:', hiddenElement);
                            console.log('隐藏字段值:', hiddenElement ? hiddenElement.value : 'null');
                            
                            // 获取面试记录ID - 多种方式确保获取到正确的ID
                            var recordId = interviewId || formData.InterviewId || (hiddenElement ? hiddenElement.value : null);
                            console.log('最终使用的ID:', recordId, '类型:', typeof recordId);
                            
                            if(!recordId) {
                                layer.msg('无法获取面试记录ID，请重新打开反馈窗口', {icon: 2});
                                return false;
                            }
                            
                            // 构建更新数据 - 只传必要的三个字段
                            var updateData = {
                                Id: parseInt(recordId),
                                InterviewFeedback: formData.interviewFeedback || '',
                                InterviewResult: formData.interviewResult || ''
                            };
                            
                            // 获取防伪标记
                            var token = $('input[name="__RequestVerificationToken"]').val();
                            updateData.__RequestVerificationToken = token;
                            
                            console.log('发送更新数据:', updateData);
                            
                            // 调用后台接口更新面试信息
                            $.ajax({
                                url: '/InterviewMenagement/UpdateInterviewMenagement',
                                type: 'POST',
                                data: updateData,
                                beforeSend: function() {
                                    layer.load(1, {shade: [0.3, '#000']});
                                },
                                success: function(res) {
                                    layer.closeAll('loading');
                                    console.log('面试反馈更新响应:', res);
                                    
                                    if(res.success || res > 0) {
                                        layer.msg('面试反馈提交成功', {
                                            icon: 1,
                                            time: 1500
                                        }, function() {
                                            layer.close(index);
                                            // 重新加载数据
                                            loadInterviewData();
                                        });
                                    } else {
                                        layer.msg(res.message || '面试反馈提交失败', {icon: 2});
                                    }
                                },
                                error: function(xhr, status, error) {
                                    layer.closeAll('loading');
                                    console.error('Error:', xhr.responseText);
                                    var errorMessage = '服务器错误';
                                    try {
                                        if (xhr.responseText) {
                                            var response = JSON.parse(xhr.responseText);
                                            errorMessage = response.message || response.error || '面试反馈提交失败';
                                        }
                                    } catch (e) {
                                        console.error('解析错误信息失败:', e);
                                        errorMessage = '提交失败，请检查输入数据';
                                    }
                                    layer.msg(errorMessage, {icon: 2});
                                }
                            });
                            
                            return false;
                        });
                    }
                });
            }

            // 显示面试邀请弹窗
            function showInterviewInviteModal(personnelId) {
                // 计算弹窗尺寸
                var windowWidth = window.innerWidth || document.documentElement.clientWidth;
                var windowHeight = window.innerHeight || document.documentElement.clientHeight;
                
                var modalWidth, modalHeight;
                
                if (windowWidth <= 768) {
                    // 小屏幕：几乎全屏
                    modalWidth = Math.min(windowWidth * 0.95, 600) + 'px';
                    modalHeight = Math.min(windowHeight * 0.9, 700) + 'px';
                } else if (windowWidth <= 1200) {
                    // 中等屏幕
                    modalWidth = Math.min(windowWidth * 0.9, 900) + 'px';
                    modalHeight = Math.min(windowHeight * 0.85, 750) + 'px';
                } else {
                    // 大屏幕
                    modalWidth = '1100px';
                    modalHeight = '750px';
                }
                
                // 打开面试邀请弹窗
                layer.open({
                    type: 1,
                    title: '<i class="layui-icon layui-icon-date"></i> 邀请面试',
                    area: [modalWidth, modalHeight],
                    resize: false,
                    maxmin: true,
                    content: `
                        <div style="height: 100%; display: flex; flex-direction: column;">
                            <form class="layui-form" style="height: 100%; display: flex; flex-direction: column;">
                                <input type="hidden" name="PersonnelId" value="${personnelId}">
                                
                                                                <div class="modal-content-responsive" style="flex: 1; padding: 25px 30px; overflow-y: auto;">
                                    <div class="modal-form-grid">
                                    <!-- 第一行：人员编码、人员名称、联系电话 -->
                                    <div class="layui-row layui-col-space20" style="margin-bottom: 20px;">
                                        <div class="layui-col-md4 layui-col-sm6 layui-col-xs12">
                                            <div class="layui-form-item" style="margin-bottom: 0;">
                                                <label class="layui-form-label" style="color: red; width: 100px; font-weight: 500; font-size: 14px;">人员编码</label>
                                                <div class="layui-input-block" style="margin-left: 120px;">
                                                    <input type="text" name="personnelCode" placeholder="请输入人员编码" class="layui-input" lay-verify="required" style="height: 38px;">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="layui-col-md4 layui-col-sm6 layui-col-xs12">
                                            <div class="layui-form-item" style="margin-bottom: 0;">
                                                <label class="layui-form-label" style="color: red; width: 100px; font-weight: 500; font-size: 14px;">人员名称</label>
                                                <div class="layui-input-block" style="margin-left: 120px;">
                                                    <input type="text" name="personnelName" placeholder="请输入人员名称" class="layui-input" lay-verify="required" style="height: 38px;">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="layui-col-md4 layui-col-sm12 layui-col-xs12">
                                            <div class="layui-form-item" style="margin-bottom: 0;">
                                                <label class="layui-form-label" style="color: red; width: 100px; font-weight: 500; font-size: 14px;">联系电话</label>
                                                <div class="layui-input-block" style="margin-left: 120px;">
                                                    <input type="text" name="phone" placeholder="请输入联系电话" class="layui-input" lay-verify="required|phone" style="height: 38px;">
                                                </div>
                                            </div>
                                        </div>                                     
                                    </div>
                                    
                                    <!-- 第二行：归属部门、岗位、角色 -->
                                    <div class="layui-row layui-col-space20" style="margin-bottom: 20px;">
                                        <div class="layui-col-md4 layui-col-sm6 layui-col-xs12">
                                            <div class="layui-form-item" style="margin-bottom: 0;">
                                                <label class="layui-form-label" style="color: red; width: 100px; font-weight: 500; font-size: 14px;">归属部门</label>
                                                <div class="layui-input-block" style="margin-left: 120px;">
                                                     <select name="departmentId" id="departmentSelect" lay-verify="required" style="height: 38px;">
                                                         <option value="">请选择归属部门</option>
                                                     </select>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="layui-col-md4 layui-col-sm6 layui-col-xs12">
                                            <div class="layui-form-item" style="margin-bottom: 0;">
                                                <label class="layui-form-label" style="color: red; width: 100px; font-weight: 500; font-size: 14px;">岗位</label>
                                                <div class="layui-input-block" style="margin-left: 120px;">
                                                    <select name="position" lay-verify="required" style="height: 38px;">
                                                        <option value="">请选择岗位</option>
                                                        <option value="注塑机操作工">注塑机操作工</option>
                                                        <option value="部门经理">部门经理</option>
                                                        <option value="喷砂清洗操作工">喷砂清洗操作工</option>
                                                        <option value="组装机操作工">组装机操作工</option>
                                                        <option value="检测员">检测员</option>
                                                        <option value="包装工">包装工</option>
                                                        <option value="测试经理">测试经理</option>
                                                        <option value="纺工">纺工</option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="layui-col-md4 layui-col-sm12 layui-col-xs12">
                                            <div class="layui-form-item" style="margin-bottom: 0;">
                                                <label class="layui-form-label" style="color: red; width: 100px; font-weight: 500; font-size: 14px;">角色</label>
                                                <div class="layui-input-block" style="margin-left: 120px;">
                                                     <select name="roleId" id="roleSelect" lay-verify="required" style="height: 38px;">
                                                         <option value="">请选择角色</option>
                                                     </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    
                                                                        <!-- 第三行：面试官、面试时间、面试次数 -->
                                    <div class="layui-row layui-col-space20" style="margin-bottom: 20px;">
                                        <div class="layui-col-md4 layui-col-sm6 layui-col-xs12">
                                            <div class="layui-form-item" style="margin-bottom: 0;">
                                                <label class="layui-form-label" style="color: red; width: 100px; font-weight: 500; font-size: 14px;">面试官</label>
                                                <div class="layui-input-block" style="margin-left: 120px;">
                                                     <input type="hidden" name="interviewerId" id="interviewerIdInput">
                                                     <div class="layui-input-inline" style="width: calc(100% - 40px);">
                                                         <input type="text" name="interviewer" id="interviewerInput" placeholder="请选择面试官" class="layui-input" lay-verify="required" readonly style="height: 38px;">
                                                     </div>
                                                     <div class="layui-input-inline" style="width: 38px; margin-left: 2px;">
                                                         <button type="button" class="layui-btn layui-btn-primary" style="width: 38px; height: 38px; padding: 0;" id="selectInterviewerBtn">
                                                             <i class="layui-icon layui-icon-search"></i>
                                                         </button>
                                                     </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="layui-col-md4 layui-col-sm6 layui-col-xs12">
                                            <div class="layui-form-item" style="margin-bottom: 0;">
                                                <label class="layui-form-label" style="color: red; width: 100px; font-weight: 500; font-size: 14px;">面试时间</label>
                                                <div class="layui-input-block" style="margin-left: 120px;">
                                                    <input type="text" name="interviewTime" placeholder="请选择面试时间" class="layui-input" id="interviewTime" readonly lay-verify="required" style="height: 38px;">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="layui-col-md4 layui-col-sm12 layui-col-xs12">
                                            <div class="layui-form-item" style="margin-bottom: 0;">
                                                <label class="layui-form-label" style="color: red; width: 100px; font-weight: 500; font-size: 14px;">面试次数</label>
                                                <div class="layui-input-block" style="margin-left: 120px;">
                                                    <input type="number" name="interviewCount" placeholder="请输入面试次数" class="layui-input" lay-verify="required" style="height: 38px;">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    
                                    <!-- 第四行：定级级别 -->
                                    <div class="layui-row layui-col-space20" style="margin-bottom: 20px;">
                                        <div class="layui-col-md4 layui-col-sm12 layui-col-xs12">
                                            <div class="layui-form-item" style="margin-bottom: 0;">
                                                <label class="layui-form-label" style="width: 100px; font-weight: 500; font-size: 14px;">定级级别</label>
                                                <div class="layui-input-block" style="margin-left: 120px;">
                                                    <select name="gradeLevel" style="height: 38px;">
                                                        <option value="">请选择职级</option>
                                                        <option value="初级">初级</option>
                                                        <option value="中级">中级</option>
                                                        <option value="高级">高级</option>
                                                        <option value="资深">资深</option>
                                                        <option value="专家">专家</option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    
                                    </div>
                                </div>
                                
                                <div style="padding: 20px 30px; border-top: 1px solid #e6e6e6; text-align: center; flex-shrink: 0; background: #fafafa;">
                                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="interviewInviteForm" style="height: 40px; padding: 0 30px; margin-right: 15px; font-size: 14px; border-radius: 4px;">
                                        <i class="layui-icon layui-icon-ok"></i> 发送邀请
                                    </button>
                                    <button type="button" class="layui-btn layui-btn-primary" onclick="layer.closeAll()" style="height: 40px; padding: 0 30px; font-size: 14px; border-radius: 4px;">
                                        <i class="layui-icon layui-icon-close"></i> 取消
                                    </button>
                                </div>
                            </form>
                        </div>
                    `,
                    success: function(layero, index){
                        // 查找对应人员的所有面试记录，找到面试次数最大的那条
                        var allPersonnelRecords = [];
                        var targetPersonnelName = '';
                        
                        // 首先找到点击的这条记录，获取人员名称
                        for(var i = 0; i < rawData.length; i++) {
                            if(rawData[i].id === personnelId) {
                                targetPersonnelName = rawData[i].personnelName;
                                break;
                            }
                        }
                        
                        // 找到同一人员的所有面试记录
                        if(targetPersonnelName) {
                            for(var i = 0; i < rawData.length; i++) {
                                if(rawData[i].personnelName === targetPersonnelName) {
                                    allPersonnelRecords.push(rawData[i]);
                                }
                            }
                        }
                        
                        // 找到面试次数最大的记录
                        var latestRecord = null;
                        if(allPersonnelRecords.length > 0) {
                            latestRecord = allPersonnelRecords[0];
                            for(var i = 1; i < allPersonnelRecords.length; i++) {
                                var currentCount = parseInt(allPersonnelRecords[i].interviewsNumber) || 0;
                                var latestCount = parseInt(latestRecord.interviewsNumber) || 0;
                                if(currentCount > latestCount) {
                                    latestRecord = allPersonnelRecords[i];
                                }
                            }
                        }
                        
                        console.log('=== 预填充调试信息 ===');
                        console.log('人员姓名:', targetPersonnelName);
                        console.log('该人员所有面试记录:', allPersonnelRecords);
                        console.log('面试次数详情:', allPersonnelRecords.map(function(r) {
                            return {
                                id: r.id,
                                name: r.personnelName,
                                interviewsNumber: r.interviewsNumber,
                                type: typeof r.interviewsNumber
                            };
                        }));
                        console.log('面试次数最大的记录:', latestRecord);
                        
                        // 预填充最新的面试信息
                        if(latestRecord) {
                            // 基本信息
                            if(latestRecord.personnelCode) {
                                layero.find('input[name="personnelCode"]').val(latestRecord.personnelCode);
                            }
                            if(latestRecord.personnelName) {
                                layero.find('input[name="personnelName"]').val(latestRecord.personnelName);
                            }
                            if(latestRecord.phone) {
                                layero.find('input[name="phone"]').val(latestRecord.phone);
                            }
                            
                            // 部门信息（如果有的话）
                            if(latestRecord.departmentId) {
                                setTimeout(function() {
                                    layero.find('select[name="departmentId"]').val(latestRecord.departmentId);
                                    form.render('select');
                                }, 500);
                            }
                            
                            // 岗位信息
                            if(latestRecord.postWage) {
                                setTimeout(function() {
                                    layero.find('select[name="position"]').val(latestRecord.postWage);
                                    form.render('select');
                                }, 300);
                            }
                            
                            // 角色信息（如果有的话）
                            if(latestRecord.rolesId) {
                                setTimeout(function() {
                                    layero.find('select[name="roleId"]').val(latestRecord.rolesId);
                                    form.render('select');
                                }, 500);
                            }
                            
                            // 面试官信息 - 通过获取所有用户信息来查找面试官姓名
                            if(latestRecord.interviewer) {
                                setTimeout(function() {
                                    var interviewerId = latestRecord.interviewer;
                                    
                                    // 获取所有用户信息，然后查找对应的面试官
                                    $.ajax({
                                        url: '/User/ShowUser',
                                        type: 'GET',
                                        dataType: 'json',
                                        success: function(users) {
                                            if(users && users.length > 0) {
                                                // 查找匹配的用户
                                                var foundUser = users.find(function(user) {
                                                    return user.id == interviewerId;
                                                });
                                                
                                                if(foundUser) {
                                                    var displayName = foundUser.userNickName || foundUser.userName || ('用户ID: ' + interviewerId);
                                                    layero.find('input[name="interviewer"]').val(displayName);
                                                    layero.find('input[name="interviewerId"]').val(interviewerId);
                                                    console.log('已设置面试官:', displayName, 'ID:', interviewerId);
                                                } else {
                                                    // 未找到对应用户，显示ID
                                                    layero.find('input[name="interviewer"]').val('面试官ID: ' + interviewerId);
                                                    layero.find('input[name="interviewerId"]').val(interviewerId);
                                                    console.log('未找到面试官用户信息，ID:', interviewerId);
                                                }
                                            } else {
                                                // 没有用户数据，显示ID
                                                layero.find('input[name="interviewer"]').val('面试官ID: ' + interviewerId);
                                                layero.find('input[name="interviewerId"]').val(interviewerId);
                                                console.log('无用户数据，使用ID:', interviewerId);
                                            }
                                        },
                                        error: function() {
                                            // 如果获取失败，显示ID
                                            layero.find('input[name="interviewer"]').val('面试官ID: ' + interviewerId);
                                            layero.find('input[name="interviewerId"]').val(interviewerId);
                                            console.log('无法获取用户信息，使用ID:', interviewerId);
                                        }
                                    });
                                }, 200);
                            }
                            
                            // 定级信息
                            if(latestRecord.definiteIntegral) {
                                setTimeout(function() {
                                    layero.find('select[name="gradeLevel"]').val(latestRecord.definiteIntegral);
                                    form.render('select');
                                }, 300);
                            }
                            
                            // 面试次数处理 - 直接使用面试次数最大的记录的面试次数（不做+1计算）
                            var currentInterviewCount = parseInt(latestRecord.interviewsNumber) || 0;
                            
                            console.log('=== 面试次数反填调试 ===');
                            console.log('面试次数最大的记录的面试次数:', currentInterviewCount);
                            console.log('反填逻辑: 直接使用最大面试次数记录的面试次数值');
                            
                            layero.find('input[name="interviewCount"]').val(currentInterviewCount);
                            
                            // 面试时间反填（如果有的话）
                            if(latestRecord.interviewsTime) {
                                setTimeout(function() {
                                    try {
                                        var interviewTime = '';
                                        console.log('原始面试时间数据:', latestRecord.interviewsTime, '类型:', typeof latestRecord.interviewsTime);
                                        
                                        if(latestRecord.interviewsTime) {
                                            var date = new Date(latestRecord.interviewsTime);
                                            console.log('解析后的日期对象:', date, '是否有效:', !isNaN(date.getTime()));
                                            
                                            if(!isNaN(date.getTime())) {
                                                // 格式化为 YYYY-MM-DD HH:mm
                                                var year = date.getFullYear();
                                                var month = (date.getMonth() + 1).toString().padStart(2, '0');
                                                var day = date.getDate().toString().padStart(2, '0');
                                                var hours = date.getHours().toString().padStart(2, '0');
                                                var minutes = date.getMinutes().toString().padStart(2, '0');
                                                interviewTime = `${year}-${month}-${day} ${hours}:${minutes}`;
                                                
                                                console.log('格式化后的时间:', interviewTime);
                                                
                                                // 设置到输入框
                                                var timeInput = layero.find('input[name="interviewTime"]');
                                                timeInput.val(interviewTime);
                                                
                                                // 触发LayUI日期选择器的更新
                                                timeInput.trigger('input');
                                                
                                                console.log('已反填面试时间:', interviewTime);
                                            } else {
                                                console.log('日期解析失败，无效的日期格式');
                                            }
                                        }
                                    } catch(e) {
                                        console.error('面试时间格式化失败:', e);
                                    }
                                }, 800); // 增加延迟，确保日期选择器已初始化
                            }
                            
                            console.log('已预填充信息:');
                            console.log('- 人员编码:', latestRecord.personnelCode);
                            console.log('- 人员名称:', latestRecord.personnelName);
                            console.log('- 联系电话:', latestRecord.phone);
                            console.log('- 部门ID:', latestRecord.departmentId);
                            console.log('- 岗位:', latestRecord.postWage);
                            console.log('- 角色ID:', latestRecord.rolesId);
                            console.log('- 面试官ID:', latestRecord.interviewer);
                            console.log('- 面试时间:', latestRecord.interviewsTime);
                            console.log('- 定级:', latestRecord.definiteIntegral);
                            console.log('- 反填的面试次数:', currentInterviewCount);
                        }
                        
                        // 获取部门数据
                        $.ajax({
                            url: '/InterviewMenagement/GetDepartmentModel',
                            type: 'GET',
                            dataType: 'json',
                            success: function(departments) {
                                console.log('获取部门数据成功:', departments);
                                var departmentSelect = layero.find('#departmentSelect');
                                
                                // 清空现有选项（保留默认选项）
                                departmentSelect.find('option:not(:first)').remove();
                                
                                // 添加部门选项
                                if(departments && departments.length > 0) {
                                    departments.forEach(function(dept) {
                                        departmentSelect.append(`<option value="${dept.id}">${dept.departmentName}</option>`);
                                    });
                                }
                                
                                // 重新渲染下拉选择框
                                form.render('select');
                            },
                            error: function(xhr, status, error) {
                                console.log('获取部门数据失败:', error);
                                layer.msg('获取部门数据失败', {icon: 2});
                            }
                        });

                        // 获取角色数据
                        $.ajax({
                            url: '/Role/GetRoles',
                            type: 'GET',
                            dataType: 'json',
                            success: function(roles) {
                                console.log('获取角色数据成功:', roles);
                                var roleSelect = layero.find('#roleSelect');
                                
                                // 清空现有选项（保留默认选项）
                                roleSelect.find('option:not(:first)').remove();
                                
                                // 添加角色选项，只显示未删除的角色
                                if(roles && roles.length > 0) {
                                    roles.forEach(function(role) {
                                        // 过滤掉已删除的角色
                                        if(!role.isDelete) {
                                            roleSelect.append(`<option value="${role.id}">${role.roleName}</option>`);
                                        }
                                    });
                                }
                                
                                // 重新渲染下拉选择框
                                form.render('select');
                            },
                            error: function(xhr, status, error) {
                                console.log('获取角色数据失败:', error);
                                layer.msg('获取角色数据失败', {icon: 2});
                            }
                        });
                        
                        // 重新渲染表单元素
                        form.render();
                        
                        // 添加电话号码验证规则
                        form.verify({
                            phone: function(value){
                                if(value && !/^1[3-9]\d{9}$/.test(value)){
                                    return '请输入正确的手机号码格式';
                                }
                            }
                        });
                        
                        // 初始化日期时间选择器
                        layui.use('laydate', function(){
                            var laydate = layui.laydate;
                            // 获取当前时间，并设置为最小可选时间
                            var now = new Date();
                            var today = now.getFullYear() + '-' + 
                                       (now.getMonth() + 1).toString().padStart(2, '0') + '-' + 
                                       now.getDate().toString().padStart(2, '0');
                            
                            laydate.render({
                                elem: '#interviewTime',
                                type: 'datetime',
                                format: 'yyyy-MM-dd HH:mm',
                                min: today, // 最小可选日期为今天
                                btns: ['clear', 'now', 'confirm'],
                                done: function(value, date, endDate){
                                    console.log('选择的面试时间:', value);
                                    // 验证选择的时间是否有效
                                    if(value) {
                                        console.log('面试时间已选择:', value);
                                    }
                                }
                            });
                        });
                        
                        // 监听面试官选择按钮
                        layero.find('#selectInterviewerBtn').on('click', function() {
                            showUserSelectionModal();
                        });

                        // 监听表单提交
                        form.on('submit(interviewInviteForm)', function(data) {
                            var formData = data.field;
                            console.log('面试邀请数据:', formData);
                            console.log('面试官ID:', formData.interviewerId);
                            console.log('面试官名称:', formData.interviewer);
                            
                            if(!formData.interviewTime) {
                                layer.msg('请选择面试时间', {icon: 2});
                                return false;
                            }
                            
                            if(!formData.interviewerId) {
                                layer.msg('请选择面试官', {icon: 2});
                                return false;
                            }
                            
                            // 构建符合后端DTO的数据格式（PascalCase - 大写开头）
                            var requestData = {
                                PersonnelCode: formData.personnelCode || '',
                                PersonnelName: formData.personnelName || '',
                                Phone: formData.phone || '', // 从表单中获取电话号码
                                Sex: 0, // 根据人员信息从现有数据中获取
                                DefiniteIntegral: formData.gradeLevel || '',
                                DepartmentId: null, // 部门ID（int?类型）
                                PostWage: formData.position || '', 
                                RolesId: null, // 角色ID（int?类型）
                                Interviewer: null, // 面试官用户编号（int?类型）
                                InterviewFeedback: '', // 设置为空值
                                InterviewResult: '待选', // 默认状态
                                InterviewsNumber: parseInt(formData.interviewCount) || 1,
                                InterviewsTime: formData.interviewTime || new Date().toISOString(),
                                Remark: '' // 备注设置为空值
                            };
                            
                            // 使用最新的面试记录信息（已经在弹窗打开时获取）
                            // 重新查找该人员面试次数最大的记录以获取完整信息
                            var targetPersonnelName = formData.personnelName;
                            var latestPersonnelRecord = null;
                            
                            if(targetPersonnelName) {
                                var allPersonnelRecords = rawData.filter(function(item) {
                                    return item.personnelName === targetPersonnelName;
                                });
                                
                                if(allPersonnelRecords.length > 0) {
                                    latestPersonnelRecord = allPersonnelRecords[0];
                                    for(var i = 1; i < allPersonnelRecords.length; i++) {
                                        var currentCount = parseInt(allPersonnelRecords[i].interviewsNumber) || 0;
                                        var latestCount = parseInt(latestPersonnelRecord.interviewsNumber) || 0;
                                        if(currentCount > latestCount) {
                                            latestPersonnelRecord = allPersonnelRecords[i];
                                        }
                                    }
                                }
                            }
                            
                            if(latestPersonnelRecord) {
                                requestData.Sex = latestPersonnelRecord.sex || 0;
                            }
                            
                            // 获取部门ID
                            var selectedDepartmentOption = document.querySelector('#departmentSelect option:checked');
                            if(selectedDepartmentOption && selectedDepartmentOption.value) {
                                requestData.DepartmentId = parseInt(selectedDepartmentOption.value);
                            }
                            
                            // 获取角色ID
                            var selectedRoleOption = document.querySelector('#roleSelect option:checked');
                            if(selectedRoleOption && selectedRoleOption.value) {
                                requestData.RolesId = parseInt(selectedRoleOption.value);
                            }
                            
                            // 获取面试官ID
                            if(formData.interviewerId) {
                                requestData.Interviewer = parseInt(formData.interviewerId);
                            }
                            
                            console.log('发送到后端的数据:', requestData);
                            
                            // 获取防伪标记并添加到请求数据中
                            var token = $('input[name="__RequestVerificationToken"]').val();
                            requestData.__RequestVerificationToken = token;
                            
                            // 调用后台接口添加面试记录
                            $.ajax({
                                url: '/InterviewMenagement/AddInterviewMenagement',
                                type: 'POST',
                                data: requestData,
                                beforeSend: function() {
                                    layer.load(1, {shade: [0.3, '#000']});
                                },
                                success: function(res) {
                                    layer.closeAll('loading');
                                    console.log('面试记录添加响应:', res);
                                    
                                    // 根据项目其他页面的模式，检查res.success或数值结果
                                    if(res.success || res > 0) {
                                        layer.msg('面试邀请发送成功', {
                                            icon: 1,
                                            time: 1500
                                        }, function() {
                                            layer.close(index);
                                            // 重新加载数据
                                            loadInterviewData();
                                        });
                                    } else {
                                        layer.msg(res.message || '面试邀请发送失败', {icon: 2});
                                    }
                                },
                                error: function(xhr, status, error) {
                                    layer.closeAll('loading');
                                    console.error('Error:', xhr.responseText);
                                    var errorMessage = '服务器错误';
                                    try {
                                        if (xhr.responseText) {
                                            var response = JSON.parse(xhr.responseText);
                                            errorMessage = response.message || response.error || '面试邀请发送失败';
                                        }
                                    } catch (e) {
                                        console.error('解析错误信息失败:', e);
                                        errorMessage = '提交失败，请检查输入数据';
                                    }
                                    layer.msg(errorMessage, {icon: 2});
                                }
                            });
                            
                            return false;
                        });
                    }
                });
            }

            // 显示人员选择弹窗
            function showUserSelectionModal() {
                // 计算人员选择弹窗尺寸
                var windowWidth = window.innerWidth || document.documentElement.clientWidth;
                var windowHeight = window.innerHeight || document.documentElement.clientHeight;
                
                var userModalWidth, userModalHeight;
                
                if (windowWidth <= 768) {
                    // 小屏幕
                    userModalWidth = Math.min(windowWidth * 0.95, 500) + 'px';
                    userModalHeight = Math.min(windowHeight * 0.8, 500) + 'px';
                } else if (windowWidth <= 1024) {
                    // 中等屏幕
                    userModalWidth = Math.min(windowWidth * 0.85, 700) + 'px';
                    userModalHeight = Math.min(windowHeight * 0.8, 600) + 'px';
                } else {
                    // 大屏幕
                    userModalWidth = '800px';
                    userModalHeight = '600px';
                }
                
                var userSelectionIndex = layer.open({
                    type: 1,
                    title: '<i class="layui-icon layui-icon-username"></i> 人员选择',
                    area: [userModalWidth, userModalHeight],
                    resize: false,
                    maxmin: true,
                    content: `
                        <div style="height: 100%; display: flex; flex-direction: column;">
                            <!-- 搜索区域 -->
                            <div style="padding: 15px; border-bottom: 1px solid #eee; flex-shrink: 0;">
                                <form class="layui-form layui-form-pane" lay-filter="userSearchForm">
                                    <div class="layui-form-item" style="margin-bottom: 10px;">
                                         <div class="layui-input-inline" style="width: 150px;">
                                             <input type="text" name="userName" placeholder="请输入用户名称" class="layui-input">
                                         </div>
                                         <div class="layui-input-inline" style="width: 150px;">
                                             <input type="text" name="userNickName" placeholder="请输入用户昵称" class="layui-input">
                                         </div>
                                         <div class="layui-input-inline" style="width: 150px;">
                                             <input type="text" name="userPhone" placeholder="请输入手机号码" class="layui-input">
                                         </div>
                                        <div class="layui-input-inline">
                                            <button class="layui-btn" lay-submit lay-filter="userSearch">
                                                <i class="layui-icon layui-icon-search"></i> 搜索
                                            </button>
                                            <button type="reset" class="layui-btn layui-btn-primary" id="userResetBtn">
                                                <i class="layui-icon layui-icon-refresh"></i> 重置
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            
                            <!-- 用户列表区域 -->
                            <div style="flex: 1; padding: 15px; overflow-y: auto;">
                                <table class="layui-table" lay-skin="line" style="margin: 0;">
                                    <thead>
                                        <tr>
                                            <th width="120">用户名称</th>
                                            <th width="120">用户昵称</th>
                                            <th width="150">部门</th>
                                            <th width="120">手机号码</th>
                                            <th width="80">操作</th>
                                        </tr>
                                    </thead>
                                    <tbody id="userTableBody">
                                        <!-- 用户数据将通过JavaScript动态生成 -->
                                    </tbody>
                                </table>
                            </div>
                            
                            <!-- 分页区域 -->
                            <div style="padding: 10px; border-top: 1px solid #eee; text-align: center; flex-shrink: 0;">
                                <div id="userPagination"></div>
                            </div>
                            
                            <!-- 底部按钮 -->
                            <div style="padding: 15px; border-top: 1px solid #eee; text-align: center; flex-shrink: 0; background: #f8f9fa;">
                                <button type="button" class="layui-btn layui-btn-primary" onclick="layer.close(window.currentUserSelectionIndex)">
                                    <i class="layui-icon layui-icon-close"></i> 取消
                                </button>
                            </div>
                        </div>
                    `,
                    success: function(layero, index){
                        // 保存弹窗索引供全局使用
                        window.currentUserSelectionIndex = index;
                        
                        // 重新渲染表单
                        form.render();
                        
                        // 加载用户数据
                        loadUserData();
                        
                        // 监听搜索
                        form.on('submit(userSearch)', function(data){
                            var searchData = data.field;
                            console.log('用户搜索条件:', searchData);
                            loadUserDataWithSearch(searchData);
                            return false;
                        });
                        
                        // 监听重置
                        layero.find('#userResetBtn').on('click', function(){
                            setTimeout(function(){
                                loadUserData();
                            }, 100);
                        });
                    }
                });
            }

            // 加载用户数据
            function loadUserData() {
                loadUserDataWithSearch({});
            }

            // 带搜索条件加载用户数据
            function loadUserDataWithSearch(searchParams) {
                $.ajax({
                    url: '/User/ShowUser',
                    type: 'GET',
                    data: searchParams,
                    dataType: 'json',
                    success: function(response) {
                        // 处理返回数据格式，可能是直接数组或包含Data属性的对象
                        var users = Array.isArray(response) ? response : 
                                  (response && response.data ? response.data : 
                                   (response && response.Data ? response.Data : []));
                        renderUserTable(users || []);
                    },
                    error: function(xhr, status, error) {
                        layer.msg('获取用户数据失败，请稍后重试', {icon: 2});
                        renderUserTable([]);
                    }
                });
            }

            // 渲染用户表格
            function renderUserTable(users) {
                var tbody = document.getElementById('userTableBody');
                if(!tbody) return;
                
                tbody.innerHTML = '';

                if(!users || users.length === 0) {
                    var emptyRow = document.createElement('tr');
                    emptyRow.innerHTML = `
                        <td colspan="5" style="text-align: center; padding: 30px; color: #999;">
                            <i class="layui-icon layui-icon-face-cry" style="font-size: 32px; display: block; margin-bottom: 10px;"></i>
                            暂无用户数据
                        </td>
                    `;
                    tbody.appendChild(emptyRow);
                    return;
                }

                users.forEach(function(user) {
                    var tr = document.createElement('tr');
                    tr.innerHTML = `
                        <td>${user.userName || ''}</td>
                        <td>${user.userNickName || ''}</td>
                        <td>${user.departmentName || ''}</td>
                        <td>${user.userPhone || ''}</td>
                        <td style="text-align: center;">
                            <button class="layui-btn layui-btn-xs layui-btn-normal" 
                                    data-username="${(user.userName || '').replace(/"/g, '&quot;')}" 
                                    data-usernickname="${(user.userNickName || '').replace(/"/g, '&quot;')}" 
                                    data-userid="${user.id || ''}" 
                                    onclick="selectUserFromData(this, window.currentUserSelectionIndex)">
                                选择
                            </button>
                        </td>
                    `;
                    tbody.appendChild(tr);
                });
                
                // 重新渲染LayUI组件
                form.render();
            }

            // 从按钮数据属性选择用户
            window.selectUserFromData = function(buttonElement, layerIndex) {
                var userName = buttonElement.getAttribute('data-username') || '';
                var userNickName = buttonElement.getAttribute('data-usernickname') || '';
                var userId = buttonElement.getAttribute('data-userid') || '';
                
                selectUser(userName, userNickName, userId, layerIndex);
            };

            // 选择用户
            window.selectUser = function(userName, userNickName, userId, layerIndex) {
                console.log('选择用户:', {userName: userName, userNickName: userNickName, userId: userId, layerIndex: layerIndex});
                
                // 将用户昵称填入面试官输入框（优先显示昵称，如果没有昵称则显示用户名）
                var displayName = userNickName || userName;
                var interviewerInput = document.getElementById('interviewerInput');
                if(interviewerInput) {
                    interviewerInput.value = displayName;
                }
                
                // 将用户ID填入隐藏字段
                var interviewerIdInput = document.getElementById('interviewerIdInput');
                if(interviewerIdInput) {
                    interviewerIdInput.value = userId;
                }
                
                console.log('已设置面试官:', {displayName: displayName, userName: userName, userNickName: userNickName, id: userId});
                
                // 只关闭人员选择弹窗
                if(layerIndex) {
                    layer.close(layerIndex);
                } else {
                    // 如果没有传递索引，则查找并关闭人员选择弹窗
                    var layerObj = layer.getChildFrame('[title*="人员选择"]');
                    if(layerObj && layerObj.length > 0) {
                        layer.close(layerObj.attr('id'));
                    }
                }
                
                layer.msg('已选择面试官: ' + displayName, {icon: 1, time: 1500});
            };

            // 搜索
            form.on('submit(search)', function(data){
                var searchData = data.field;
                console.log('搜索条件:', searchData);
                
                // 调用带搜索参数的接口，从第一页开始搜索
                loadInterviewDataWithSearch(searchData, 1, 10);
                return false;
            });

            // 带搜索条件的数据加载
            function loadInterviewDataWithSearch(searchParams, page, limit) {
                // 设置默认分页参数
                page = page || 1;
                limit = limit || 10;
                
                // 保存当前分页信息
                currentPaginationInfo = { page: page, limit: limit };
                
                // 合并搜索参数和分页参数
                var requestParams = Object.assign({}, searchParams, {
                    page: page,
                    limit: limit
                });
                
                // 首先调用第一个接口进行搜索
                $.ajax({
                    url: '/InterviewMenagement/GetInterviewMenagementModel',
                    type: 'GET',
                    data: requestParams,
                    dataType: 'json',
                    success: function(response) {
                        console.log('搜索结果:', response);
                        // 处理分页响应格式
                        var allData = [];
                        if (response && response.listDate) {
                            allData = response.listDate;
                        } else if (Array.isArray(response)) {
                            allData = response;
                        }
                        
                        // 分离面试次数为0和不为0的数据
                        var zeroInterviewData = [];
                        var nonZeroInterviewData = [];
                        
                        allData.forEach(function(item) {
                            var interviewCount = parseInt(item.interviewsNumber) || 0;
                            if (interviewCount === 0) {
                                zeroInterviewData.push(item);
                            } else {
                                nonZeroInterviewData.push(item);
                            }
                        });
                        
                        // 如果有面试次数不为0的数据，调用第二个接口获取带部门信息的数据
                        if (nonZeroInterviewData.length > 0) {
                            var nonZeroIds = nonZeroInterviewData.map(function(item) {
                                return item.id;
                            });
                            
                            // 调用第二个接口获取带部门信息的搜索结果
                            var searchParamsWithDept = Object.assign({}, searchParams, {
                                includeIds: nonZeroIds.join(','),
                                includeDepartment: true,
                                page: page,
                                limit: limit
                            });
                            
                            $.ajax({
                                url: '/InterviewMenagement/GetInterviewMenagementModelWithDepartment', // 第二个接口：带部门信息的接口
                                type: 'GET',
                                data: searchParamsWithDept,
                                dataType: 'json',
                                success: function(departmentResponse) {
                                    // 处理第二个接口的分页响应格式
                                    var departmentData = [];
                                    if (departmentResponse && departmentResponse.listDate) {
                                        departmentData = departmentResponse.listDate;
                                    } else if (Array.isArray(departmentResponse)) {
                                        departmentData = departmentResponse;
                                    }
                                    rawData = [...zeroInterviewData, ...departmentData];
                                    // 传递第一个接口的分页信息
                                    var paginationInfo = {
                                        currentPage: page,
                                        totalPages: response.pageIndex || 1,  // pageIndex是总页数
                                        totalCount: response.pageCount || 0,  // pageCount是总行数
                                        limit: limit
                                    };
                                    processSearchResultsAndRender(paginationInfo);
                                },
                                error: function(xhr, status, error) {
                                    console.log('获取带部门信息的搜索结果失败，使用原始搜索结果:', error);
                                    rawData = allData;
                                    var paginationInfo = {
                                        currentPage: page,
                                        totalPages: response.pageIndex || 1,  // pageIndex是总页数
                                        totalCount: response.pageCount || 0,  // pageCount是总行数
                                        limit: limit
                                    };
                                    processSearchResultsAndRender(paginationInfo);
                                }
                            });
                        } else {
                            rawData = allData;
                            var paginationInfo = {
                                pageIndex: response.pageIndex || 1,
                                pageCount: response.pageCount || 1,
                                limit: limit
                            };
                            processSearchResultsAndRender(paginationInfo);
                        }
                    },
                    error: function(xhr, status, error) {
                        console.log('搜索失败:', error);
                        layer.msg('搜索失败，请稍后重试', {icon: 2});
                    }
                });
            }

            // 处理搜索结果并渲染
            function processSearchResultsAndRender(paginationInfo) {
                console.log('最终搜索结果:', rawData);
                console.log('搜索分页信息:', paginationInfo);
                
                // 转换数据格式
                var convertedData = convertApiDataToTableData(rawData);
                
                // 按人员分组
                processedData = groupByName(convertedData);
                
                // 渲染表格
                renderTable(processedData);
                
                // 更新分页信息 - 使用服务器返回的分页信息
                if (paginationInfo && paginationInfo.totalCount) {
                    updatePagination(paginationInfo.totalCount, paginationInfo);
                } else {
                    updatePagination(rawData.length);
                }
                
                if(rawData.length === 0) {
                    layer.msg('未找到符合条件的数据', {icon: 0});
                }
            }

            // 新增按钮
            document.getElementById('addBtn').addEventListener('click', function(){
                layer.msg('新增功能待开发');
            });

            // 重置按钮
            document.getElementById('resetBtn').addEventListener('click', function(){
                // 延迟执行，等待表单重置完成
                setTimeout(function(){
                    loadInterviewData(1, 10);
                }, 100);
            });

                        // 更新分页信息
            function updatePagination(totalCount, paginationInfo) {
                var currentPage = 1;
                var pageSize = 10;
                
                // 如果有分页信息，使用服务器返回的分页数据
                if (paginationInfo) {
                    currentPage = paginationInfo.currentPage || 1;
                    pageSize = paginationInfo.limit || 10;
                    totalCount = paginationInfo.totalCount || 0; // 直接使用总行数
                }
                
                laypage.render({
                    elem: 'pagination',
                    count: totalCount,
                    curr: currentPage,
                    limit: pageSize,
                    layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'],
                    jump: function(obj, first){
                        if(!first){
                            // 重新加载数据
                            console.log('分页跳转：', obj.curr, obj.limit);
                            // 判断是搜索状态还是普通加载状态
                            var searchForm = document.querySelector('form[lay-filter="searchForm"]');
                            var formData = new FormData(searchForm);
                            var searchParams = {};
                            for (var [key, value] of formData.entries()) {
                                if (value.trim()) {
                                    searchParams[key] = value.trim();
                                }
                            }
                            
                            if (Object.keys(searchParams).length > 0) {
                                // 有搜索条件，执行搜索
                                loadInterviewDataWithSearch(searchParams, obj.curr, obj.limit);
                            } else {
                                // 无搜索条件，普通加载
                                loadInterviewData(obj.curr, obj.limit);
                            }
                        }
                    }
                });
            }

            // 初始化加载数据
            loadInterviewData(1, 10);

            // 窗口大小改变时的处理
            window.addEventListener('resize', function() {
                // 延迟执行，避免频繁触发
                clearTimeout(window.resizeTimer);
                window.resizeTimer = setTimeout(function() {
                    // 可以在这里添加窗口大小改变后的处理逻辑
                    console.log('窗口大小已改变');
                }, 200);
            });

            // 获取当前页码
            function getCurrentPage() {
                return currentPaginationInfo.page || 1;
            }

            // 获取当前每页数量
            function getCurrentLimit() {
                return currentPaginationInfo.limit || 10;
            }

            // 按人员名称分组数据的函数（用于后端数据处理）
            function groupByName(data) {
                console.log('=== 分组函数调试信息 ===');
                console.log('输入数据:', data);
                console.log('输入数据中的ID:', data.map(function(item) { return {name: item.name, id: item.id, type: typeof item.id}; }));
                
                var groups = {};
                var result = [];

                // 分组
                data.forEach(function(item) {
                    if (!groups[item.name]) {
                        groups[item.name] = [];
                    }
                    groups[item.name].push(item);
                });

                // 转换为树形结构
                Object.keys(groups).forEach(function(name) {
                    var interviews = groups[name];
                    
                    // 按面试次数排序，面试次数越高表示最新的面试
                    interviews.sort(function(a, b) {
                        return (a.count || 0) - (b.count || 0);
                    });

                    // 过滤出面试次数大于0的记录作为子级显示
                    var childrenWithInterviews = interviews.filter(function(item) {
                        return (item.count || 0) > 0;
                    });

                    // 取面试次数最高的（最后一次面试）作为父级显示
                    var parent = Object.assign({}, interviews[interviews.length - 1]);
                    
                    // 如果有面试次数大于0的记录，使用过滤后的记录作为子级
                    // 如果没有面试次数大于0的记录，则不显示子级（空数组）
                    parent.children = childrenWithInterviews;

                    console.log(`人员: ${name}, 面试记录数: ${interviews.length}, 有效子级数: ${childrenWithInterviews.length}, 父级面试次数: ${parent.count}`);
                    console.log(`父级ID: ${parent.id} (类型: ${typeof parent.id})`);
                    console.log(`子级ID们:`, childrenWithInterviews.map(function(child) { return {id: child.id, type: typeof child.id}; }));

                    result.push(parent);
                });

                console.log('分组结果:', result);
                return result;
            }
        });
    </script>
</body>
</html>
